<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<h1>Functional Programming in Javascript === Garbage</h1>
		<a href="https://awardwinningfjords.com/2014/04/21/functional-programming-in-javascript-equals-garbage.html">Functional Programming in Javascript === Garbage</a>
	</body>
	<script type="text/javascript">
		function reduce1(f, list, sum) {
			if(list.length < 1) {
				return sum;
			} else {
				var val = list.shift();
				return reduce1(f, list, f(val, list));
			}
		}
		var s = 0;
		var result = reduce1(function(val, list) {
			return val + list;
		}, [1, 2, 3, 4], s)

		function trampoline(f) {
			return function() {
				var result = f.apply(this, arguments);

				while(result instanceof Function) {
					result = result();
				}

				return result;
			};
		}

		var reduce2 = trampoline(function myself(f, list, sum) {
			if(list.length < 1) {
				return sum;
			} else {
				return function() {
					var val = list.shift();
					return myself(f, list, f(val, list));
				};
			}
		});

		function partial() {
			var args = Array.prototype.slice.call(arguments, 0);
			var f = args.shift();

			return function partialExecute_() {
				var args2 = Array.prototype.slice.call(arguments, 0);
				return f.apply(this, args.concat(args2));
			};
		}

		function compose() {
			var fns = Array.prototype.slice.call(arguments, 0);

			return function composedExecute_(value) {
				for(var i = fns.length - 1; i >= 0; --i) {
					value = fns[i](value);
				}
				return value;
			};
		}
	</script>

</html>